package com.mkyong.app;

import java.io.FileInputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.sdb.SDBFactory;
import com.hp.hpl.jena.sdb.Store;
import com.hp.hpl.jena.sdb.StoreDesc;
import com.hp.hpl.jena.sdb.sql.JDBC;
import com.hp.hpl.jena.sdb.sql.SDBConnection;
import com.hp.hpl.jena.sdb.store.DatabaseType;
import com.hp.hpl.jena.sdb.store.LayoutType;

public class RelationalStore extends CustomStore {

	private static StoreDesc storeDesc = new StoreDesc(
			LayoutType.LayoutTripleNodesHash, DatabaseType.MySQL);;
	private static SDBConnection conn;
	private static Store store;
	static {
		JDBC.loadDriverMySQL();
		conn = new SDBConnection(EndpointContextListner.MYSQL_DRIVER,
				EndpointContextListner.DB_USER, EndpointContextListner.DB_PSW);
		store = SDBFactory.connectStore(conn, storeDesc);
	}

	public Model getDefaultModel() {

		Model model = SDBFactory.connectDefaultModel(store);

		return model;

	}

	@Override
	public void setupStore() throws Exception {

		store.getTableFormatter().create();
		Model model = SDBFactory.connectDefaultModel(store);

		model.read(new FileInputStream(EndpointContextListner.OWL_LOCATION),
				null, "TTL");

	}

}
